home *** CD-ROM | disk | FTP | other *** search
/ Amiga Collections: Topik / Topik - Disk 02 - Fonts and CLI Commands (19xx)(Topik Public Domain)(PD)[a][WB].zip / Topik - Disk 02 - Fonts and CLI Commands (19xx)(Topik Public Domain)(PD)[a][WB].adf / Source / drive.c < prev    next >
C/C++ Source or Header  |  1989-04-21  |  5KB  |  169 lines

  1. /*
  2.  *  This program gives you information about the disks that you have
  3.  *  connected to the system.
  4.  *
  5.  *  This program is written for the public domain and is freely
  6.  *  distributable as long as credit is given to the author.  I would
  7.  *  like to thank Michael L. Hitch for his "AutoTest" program which
  8.  *  provided much insight for this program.
  9.  *
  10.  *  Written by: Rick Manazir
  11.  *  Date: 01/06/89
  12.  *
  13.  *
  14.  *                      MODIFICATION HISTORY
  15.  *
  16.  *     Date      Author                   Change Description
  17.  *   ========   ========     ============================================
  18.  *   01/06/89     RMM        Original issue
  19.  *
  20.  */
  21.  
  22. #ifndef OBSOLETE_LIBRARIES_DOS_H
  23. #define OBSOLETE_LIBRARIES_DOS_H
  24. #endif
  25.  
  26. #include <dos.h>
  27. #include <libraries/dosextens.h>
  28. #include <libraries/filehandler.h>
  29. #include <string.h>
  30. #include <stdio.h>
  31. #include <stdlib.h>
  32.  
  33. extern struct DosLibrary *DOSBase;
  34.  
  35. char name[80];
  36. char *disk_name_ptr;
  37.  
  38. void get_device_info();
  39. void quit(), cleanup();
  40.  
  41. void main(argc, argv)
  42. int argc;
  43. char *argv[];
  44. {
  45.    disk_name_ptr = argv[1];
  46.    if (argc < 2)
  47.    {
  48.       printf("Drive name: ");
  49.       fgets(name, 80,stdin);
  50.       disk_name_ptr = name;
  51.       while (*disk_name_ptr && *disk_name_ptr != '\n')
  52.          ++disk_name_ptr;
  53.       *disk_name_ptr = 0;
  54.       disk_name_ptr = name;
  55.    }
  56.    printf("\n\x1b[32mGetting data on disk %s\x1b[0m\n",disk_name_ptr);
  57.    get_device_info(disk_name_ptr);
  58.    cleanup();
  59. }
  60.  
  61. void get_device_info(disk_drive)
  62. char *disk_drive;
  63. {
  64.    struct RootNode *root;
  65.    struct DosInfo *info;
  66.    struct DeviceNode *device;
  67.    struct InfoData *disk_info;
  68.    struct FileSysStartupMsg *startup_msg;
  69.    
  70.    long lock;
  71.    unsigned long *env_ptr;
  72.    unsigned sectors_free, total_sectors, per_cent_used;
  73.       
  74.    /* Get the driver names from the device list. */
  75.    root = (struct RootNode *) DOSBase -> dl_Root;
  76.    info = (struct DosInfo *) BADDR (root -> rn_Info);
  77.    device = (struct DeviceNode *) BADDR (info -> di_DevInfo);
  78.    /* Find the device requested. */
  79.    while (device)
  80.    {
  81.       if (device -> dn_Type == DLT_DEVICE)
  82.       {
  83.          if (match (disk_drive, BADDR (device -> dn_Name) + 1) == 0) break;
  84.       }
  85.       device = (struct DeviceNode *) BADDR (device -> dn_Next);
  86.    }
  87.    lock = Lock (disk_drive, ACCESS_READ);
  88.    if (device == 0 || lock == 0)
  89.    {
  90.       printf("Device %s was not found.\n",disk_drive);
  91.       quit(1);
  92.    }
  93.    disk_info = (struct InfoData *) malloc (sizeof (struct InfoData));
  94.    if (disk_info != NULL)
  95.    {
  96.       if (Info(lock, disk_info) == 0)
  97.       {
  98.          UnLock(lock);
  99.       }
  100.    }
  101.    printf("\x1b[33mData for drive %s is:\x1b[0m\n",disk_drive);
  102.    printf("Unit Number: %d\n",disk_info -> id_UnitNumber);
  103.    printf("Number of soft errors: %d\n",disk_info -> id_NumSoftErrors);
  104.    switch (disk_info -> id_DiskState)
  105.    {
  106.       case ID_WRITE_PROTECTED:
  107.          printf("Disk State: Write Protected.\n");
  108.          break;
  109.       case ID_VALIDATING:
  110.          printf("Disk State: Currently being validated.\n");
  111.      break;
  112.       case ID_VALIDATED:
  113.          printf("Disk State: Disk is consistent and writeable.\n");
  114.    }
  115.    printf("Number of sectors: %d\n",disk_info -> id_NumBlocks);
  116.    printf("Number of bytes per sector: %d\n",disk_info -> id_BytesPerBlock);
  117.    startup_msg = (struct FileSysStartupMsg *) BADDR (device -> dn_Startup);
  118.    env_ptr = (long *) BADDR (startup_msg -> fssm_Environ);
  119.    sectors_free = disk_info -> id_NumBlocks - disk_info -> id_NumBlocksUsed;
  120.    total_sectors = (env_ptr[DE_UPPERCYL] - env_ptr[DE_LOWCYL] + 1) * env_ptr[DE_NUMHEADS] * env_ptr[DE_BLKSPERTRACK];
  121.    per_cent_used = ((total_sectors - sectors_free) * 100) / total_sectors;
  122.    printf("Number of sectors used %d\n",disk_info -> id_NumBlocksUsed);
  123.    printf("Number of free sectors: %d\n",sectors_free);
  124.    printf("Total number of sectors: %d\n",total_sectors);
  125.    printf("Per Cent of sectors used: %d\n",per_cent_used);
  126.    printf("Number of heads is: %d\n",env_ptr[DE_NUMHEADS]);
  127.    printf("Number of sectors per track: %d\n",env_ptr[DE_BLKSPERTRACK]);
  128.    printf("Number of DOS reserved sectors: %d\n",env_ptr[DE_RESERVEDBLKS]);
  129.    printf("Disk interleave: %d\n",env_ptr[DE_INTERLEAVE]);
  130.    printf("Low cylinder: %d\n",env_ptr[DE_LOWCYL]);
  131.    printf("High cylinder: %d\n",env_ptr[DE_UPPERCYL]);
  132.    printf("Number of DOS buffers: %d\n",env_ptr[DE_NUMBUFFERS]);
  133.    switch (env_ptr[DE_DOSTYPE])
  134.    {
  135.       case 0x4E952341: /* This number is incorrect in the Lattice manual. */
  136.          printf("The old slow file system.\n\n");
  137.      break;
  138.       case 0x444F5301:
  139.          printf("The new fast file system.\n\n");
  140.      break;
  141.       default:
  142.          printf("An unknown file system.\n\n");
  143.    }
  144.    if (lock) UnLock(lock);
  145. }
  146.   
  147. int match(string1, string2)
  148. register char *string1, *string2;
  149. {
  150.    register char c;
  151.    
  152.    while ((c = toupper (*string1++)) == toupper (*string2++))
  153.       if (c == 0) return(0);
  154.    if (c == ':' && !*--string2) return(0);
  155.    return(1);
  156. }
  157.  
  158. void cleanup()
  159. {
  160.    rbrk();
  161. }
  162.  
  163. void quit(code)
  164. int code;
  165. {
  166.    exit(code);
  167. }
  168.  
  169.